/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"5E10415C-9A0C-4F5C-A368-136082F42835",variableType:93}
 */
var fFecha = new Date();

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"F85285E7-87A2-45C3-88F4-785BFF385065"}
 */
var fTitulo = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"18A67623-2797-42F5-BF12-428F5ED50D1D",variableType:4}
 */
var fTipo = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4EA30528-6328-4629-B31B-27ED5B6310E8",variableType:4}
 */
var fEstado = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0B79DF30-418C-4B86-8F56-8508750157D4",variableType:4}
 */
var fOperador = null;

/**
 * @type {Number}
 * 
 * @properties={typeid:35,uuid:"AD57396B-6810-4ED0-AC3E-E322ADE1E6C5",variableType:8}
 */
var fVentana = null

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"BDC79BBF-698A-485F-A0DD-44BF9F6D44E5"}
 */
function iraDetalle(event) {
	forms.temas_dtl.controller.loadRecords(tema_id)
	forms.temas_dtl.controller.show()
}

/**
 * @properties={typeid:24,uuid:"BF6B6507-3382-4DE5-8F54-989B834B0D0E"}
 * @AllowToRunInFind
 */
function buscar() {
	var $sql = 'SELECT tema_id FROM temas WHERE (operador_id = ? or supervisor_id = ?) and '+
				'estado = ?'
	var $args = [fOperador, fOperador, fEstado]
	if (fFecha != null)
	{
		$sql += ' and fecha_proxima_accion <= ?'
		$args[$args.length] = fFecha
	}
	if (fTipo != null)
	{
		$sql += ' and tipo = ?'
		$args[$args.length] = fTipo
	}
	if (fTitulo != null)
	{
		$sql += ' and upper(titulo) like upper(?)'
		$args[$args.length] = '%' + fTitulo + '%'
	}
	
	var $ds = databaseManager.getDataSetByQuery('contador_hs',$sql,$args,-1)
	if ($ds.getMaxRowIndex() == 0)
	{
		controller.loadRecords(0)
		globals.gDialog('Aviso','No hay resultados con esas condiciones','OK')
	}
	else
		controller.loadRecords($ds)
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"DADF0232-697D-498D-BAD1-205E5C5F10B7"}
 * @AllowToRunInFind
 */
function onShow(firstShow, event) {
	buscar()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"12822D3F-A556-4C21-8C0A-C0BA116180F1"}
 */
function nuevoTema(event) {
	forms.temas_alta.controller.show()
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"75CF8016-9AD0-4BD1-BD9F-30247E16AE31"}
 */
function salir(event) {
	application.exit()
}

/**
 * Perform the element right-click action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"9980C949-2C84-4779-B187-9887F9F586D2"}
 */
function ventanaNuevaRta(event) {
	databaseManager.setAutoSave(false)
	temas_to_respuestas.newRecord()
	forms.respuestas_ventana.controller.loadRecords(temas_to_respuestas)
	plugins.window.showFormPopup(elements.fld_fecha, forms.respuestas_ventana, forms.temas_tbl, 'fVentana')
}
